package com.example.dllo.exe.fenlei;

import android.content.Intent;
import android.graphics.Color;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.example.dllo.exe.R;
import com.example.dllo.exe.fenlei.danpin.DanPinFragment;
import com.example.dllo.exe.fenlei.gonglue.GongLueFragemnt;
import com.example.dllo.exe.fenlei.xuanlishenqi.XuanLiShenQiAty;
import com.example.dllo.exe.giftspeak.GiftSpeakSouSuoAty;
import com.example.dllo.exe.main.BaseFragment;

import java.util.ArrayList;


/**
 * code is far away from bug with the animal protecting
 * <p>
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃永无BUG！  凯哥 祝你一路顺风
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 */
public  class FenLeiFragment extends BaseFragment implements TabLayout.OnTabSelectedListener, View.OnClickListener {
    private ArrayList<String> list;
    private ArrayList<Fragment> fragments;
    private TabLayout tabLayout_fenlei;
    private ViewPager viewPager_fenlei;
    private TextView textViewhide,textViewqixi;
    private FenLeiAdapter fenLeiAdapter;


    @Override
    protected int setLayout() {
        return R.layout.fenleifragmentlayout;
    }

    @Override
    protected void initView() {
        tabLayout_fenlei = bindView(R.id.tab_layout_fenleitablayout);
        viewPager_fenlei = bindView(R.id.view_pager_fenleisviewpager);
        textViewhide = bindView(R.id.fenleidanpin_hidetext);
        textViewqixi=bindView(R.id.textview_qixi);

    }

    @Override
    protected void initData() {
        fenLeiAdapter = new FenLeiAdapter(getChildFragmentManager(),getContext());
        list=new ArrayList<>();
        fragments=new ArrayList<>();
        list.add("攻略");
        list.add("单品");
        fragments.add(new GongLueFragemnt());
        fragments.add(new DanPinFragment());
        fenLeiAdapter.setList(list);
        fenLeiAdapter.setFragments(fragments);
        viewPager_fenlei.setAdapter(fenLeiAdapter);
        tabLayout_fenlei.setupWithViewPager(viewPager_fenlei);
        tabLayout_fenlei.setSelectedTabIndicatorColor(Color.WHITE);
        tabLayout_fenlei.setTabTextColors(Color.WHITE,Color.WHITE);
        textViewhide.setVisibility(View.GONE);
        tabLayout_fenlei.addOnTabSelectedListener(this);
        textViewqixi.setOnClickListener(this);
    }

    @Override
    public void onTabSelected(TabLayout.Tab tab) {

        if (tab.getPosition()==0){
        textViewhide.setVisibility(View.GONE);

        }else if (tab.getPosition()==1){
            textViewhide.setVisibility(View.VISIBLE);
        textViewhide.setOnClickListener(this);
        }
    }

    @Override
    public void onTabUnselected(TabLayout.Tab tab) {


    }

    @Override
    public void onTabReselected(TabLayout.Tab tab) {

    }


    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case  R.id.fenleidanpin_hidetext:
                Intent intent=new Intent(getContext(),XuanLiShenQiAty.class);
                startActivity(intent);


                break;
            case  R.id.textview_qixi:
                Intent intent1=new Intent(getContext(), GiftSpeakSouSuoAty.class);
                startActivity(intent1);

                break;
        }
    }
}
